package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.AppVersion;
import com.cp.admin.modular.system.service.IAppVersionService;

/**
 * app版本号控制器
 *
 * @author fengshuonan
 * @Date 2020-05-13 09:39:14
 */
@Controller
@RequestMapping("/appVersion")
public class AppVersionController extends BaseController {

    private String PREFIX = "/system/appVersion/";

    @Autowired
    private IAppVersionService appVersionService;

    /**
     * 跳转到app版本号首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "appVersion.html";
    }

    /**
     * 跳转到添加app版本号
     */
    @RequestMapping("/appVersion_add")
    public String appVersionAdd() {
        return PREFIX + "appVersion_add.html";
    }

    /**
     * 跳转到修改app版本号
     */
    @RequestMapping("/appVersion_update/{appVersionId}")
    public String appVersionUpdate(@PathVariable Long appVersionId, Model model) {
        AppVersion appVersion = appVersionService.selectById(appVersionId);
        model.addAttribute("item",appVersion);
        LogObjectHolder.me().set(appVersion);
        return PREFIX + "appVersion_edit.html";
    }

    /**
     * 获取app版本号列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return appVersionService.selectList(null);
    }

    /**
     * 新增app版本号
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AppVersion appVersion) {
        appVersionService.insert(appVersion);
        return SUCCESS_TIP;
    }

    /**
     * 删除app版本号
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long appVersionId) {
        appVersionService.deleteById(appVersionId);
        return SUCCESS_TIP;
    }

    /**
     * 修改app版本号
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AppVersion appVersion) {
        appVersionService.updateById(appVersion);
        return SUCCESS_TIP;
    }

    /**
     * app版本号详情
     */
    @RequestMapping(value = "/detail/{appVersionId}")
    @ResponseBody
    public Object detail(@PathVariable("appVersionId") Long appVersionId) {
        return appVersionService.selectById(appVersionId);
    }
}
